package lanqiao.api;

import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;

/**
 * 关于日期的api
 */
public class DateDemo {
    private static final String[] WEEKS =
            {"Sunday", "Monday", "Tuesday", "Wednesday",
                    "Thursday", "Friday", "Saturday"};

    public static void main(String[] args) {
        //两个日期相减，Date输出是毫秒
        Date d1 = new Date(2020, 7, 1, 12, 0);
        Date d2 = new Date(1921, 7, 23, 12, 0);
        long ans = d1.getTime() - d2.getTime();
        System.out.println(ans / 60000);
        System.out.println("===================================");
        System.out.println(dayOfTheWeek(10, 1, 2022));
        System.out.println(d1);
    }

    //计算日期
    public static String dayOfTheWeek(int day, int month, int year) {
        LocalDate date = LocalDate.of(year, month, day);

        // date.getDayOfWeek().getValue())该方法返回某一天是周几，范围（1-7）
        System.out.println("今天是周"+date.getDayOfWeek().getValue());
        return WEEKS[date.getDayOfWeek().getValue() % 7];
    }
}
